package com.cskaoyan.config4;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author stone
 * @date 2022/12/27 16:15
 */
@Configuration
public class DataSourceConfiguration4 {

    DataSourceProperties4 properties4;//如果它被注册为容器中组件的话，可以取出
    // 可以增加@AutoWired
    // 增加一个有参构造方法
    public DataSourceConfiguration4(DataSourceProperties4 properties4) {
        this.properties4 = properties4;
    }

    @Bean
    public DataSource dataSource4() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(properties4.getDriverClassName());
        dataSource.setUrl(properties4.getUrl());
        dataSource.setUsername(properties4.getUsername());
        dataSource.setPassword(properties4.getPassword());
        return dataSource;
    }
}
